<template>
  <div class="nav">
    <div class="banxin flex">
      <h1>
        <a href="">
          <img src="../../assets/images/indexLogo.png" alt="" />
        </a>
      </h1>
      <ul class="router-link flex">
        <!-- <li><span class="active">首页</span></li>
        <li><span>所有商品</span></li>
        <li><span>个人中心</span></li>
        <li><span>我的订单</span></li>
        <li><span>专属福利</span></li> -->
        <li v-for="item in links" :key="item.id">
          <!-- :class="{ active: $route.path === item.path }" -->
          <span
            :class="{ active: item.reg.test($route.path) }"
            @click="$router.push(item.path)"
            >{{ item.text }}</span
          >
        </li>
      </ul>
      <div class="search-bar flex">
        <input
          type="text"
          placeholder="输入搜索内容"
          v-model="keyword"
          @keyup.enter="search"
        />
        <span class="btn" @click="search"
          ><img src="../../assets/images/search.png" alt=""
        /></span>
      </div>
    </div>
    <!-- <div id="nav">
        <router-link to="/">首页</router-link> |
        <router-link to="/allgoods">所有商品</router-link> |
        <router-link to="/personal">个人中心</router-link> |
        <router-link to="/myOrders">我的订单</router-link> |
        <router-link to="/frees">专属福利</router-link>
      </div> -->
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      keyword: "",
      links: [
        { id: 1, text: "首页", path: "/home", reg: /\/home/ },
        { id: 2, text: "所有商品", path: "/allgoods", reg: /\/allgoods/ },
        { id: 3, text: "个人中心", path: "/personal/cart", reg: /\/personal/ },
        { id: 4, text: "我的订单", path: "/myOrders", reg: /\/myOrders/ },
        { id: 5, text: "专属福利", path: "/frees", reg: /\/frees/ },
      ],
    };
  },
  methods: {
    search() {
      this.$router.push(`/allgoods?keyword=${this.keyword}`);
      // this.$router.push({
      //   name: "AllGoods",
      //   query: {
      //     keyword: this.keyword,
      //   },
      // });
      this.keyword = "";
    },
  },
};
</script>
 
<style lang = "less" scoped>
.nav {
  .banxin {
    justify-content: space-between;
    padding: 14px 0;
    ul {
      padding-top: 40px;
      li {
        padding: 0 20px;
        span {
          cursor: pointer;
          font-size: 16px;
          font-family: SourceHanSansSC;
          font-weight: 500;
          color: #333;
          /* line-height: 23px; */
        }
        span {
          cursor: pointer;
          font-size: 16px;
          font-family: SourceHanSansSC;
          color: #333;
          line-height: 23px;
          &.active {
            color: #0a328e;
          }
        }
      }
    }
    .search-bar {
      padding-top: 30px;
      height: 40px;
      input {
        box-sizing: border-box;
        height: 40px;
        width: 214px;
        border-radius: 20px 0 0 20px;
        border: 1px solid #ccc;
        border-right: 0;
        padding-left: 20px;
      }
    }
    .btn {
      width: 50px;
      height: 40px;
      background-color: #0a328e;
      border-radius: 0 20px 20px 0;
      background: #0a328e;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>